<template>
  <el-date-picker
    ref="domDate"
    v-model="value"
    v-bind="$attrs"
    :type="dateType"
    :name="'c' + meta.columnId"
    :format="format"
    :value-format="valueFormat"
    :clearable="clearable"
  >
  </el-date-picker>
</template>

<script setup lang="ts" generic="T extends object">
  import type { IFormItemProps } from '../../map'
  import { itemController } from '../..map'

  defineOptions({
    name: 'nf-el-from-item-year',
    inheritAttrs: false,
  })

  const props = withDefaults(defineProps<IFormItemProps<T> & {
    format?: string,
    valueFormat?: string
  }>(), {
    meta: () => {
      return {
        colName: ''
      }
    },
    model: () => {
      return {} as T
    },
    clearable: true,
    format: 'YYYY',
    valueFormat: 'YYYY'
  }) 
  const { value } = itemController(props)

  // 根据值是否为数组，判断是否 使用范围。
  const dateType = Array.isArray(value?.value) ? 'yearrange' : 'year'

</script>
